#pragma once
#include <iostream>
#include <pthread.h>

namespace LockModule
{
    class Mutex
    {
    private:
        pthread_mutex_t _lock; //互斥锁
    public:
        Mutex(){
            int n = pthread_mutex_init(&_lock, nullptr);
            (void)n;//忽略返回值
        }
        ~Mutex(){
            int n = pthread_mutex_destroy(&_lock);
            (void)n;//忽略返回值
        }
        //禁用拷贝构造函数和赋值运算符
        Mutex(const Mutex&) = delete;
        const Mutex& operator=(const Mutex&) = delete;

        void Lock()
        {
            int n = pthread_mutex_lock(&_lock);
            (void)n;//忽略返回值
        }
        void UnLock()
        {
            int n = pthread_mutex_unlock(&_lock);
            (void)n;//忽略返回值
        }
        pthread_mutex_t* GetMutexPtr()
        {
            return &_lock;
        }
    };
}